package cn.kgc.smbms.service;

import cn.kgc.smbms.dao.UserMapper;
import cn.kgc.smbms.projo.UserExt;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import cn.kgc.smbms.projo.User;

import javax.annotation.Resource;
import java.util.List;

@Transactional
@Service
public class UserServiceImpl implements UserService {
    public UserMapper getUserMapper() {
        return userMapper;
    }

    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }
    //@Autowired和@Resource效果类似，选用@Resource为宜。
    @Resource
    private UserMapper userMapper;
   // @Resource UserExt userExt;
    @Override

    public User findUserByLogin(String userCode,String userPassword) {
        return userMapper.selectUserByLogin(userCode,userPassword);
    }
    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public boolean insertNewUser(User user) {
        boolean result=false;
        if (userMapper.insertUser(user)==1){
            result=true;
        }
        return result;
    }

    @Override
    public List<UserExt> selectUserList(int pageNo, int pageSize) {
        return userMapper.selectAll(pageNo,pageSize);
    }

    @Override
    public int selectUserCount() {
        return userMapper.selectAllUserCount();
    }
    @Override
    public int userCount(String userName,String userRole) {
        return userMapper.userCount(userName,userRole);
    }

    @Override
    public List<UserExt> selectUserLikeMoreValue(String userName, String userRole) {
        return userMapper.selectUserLikeMoreValue(userName,userRole);
    }


}
